let app = getApp()
Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function () {
    var $this = this;

    // 查看是否授权
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              $this.saveUserInfo(res.userInfo);
            }
          })
        }
      }
    })
  },
  bindGetUserInfo: function (e) {
   let userInfo = e.detail.userInfo;
    this.saveUserInfo(userInfo);
  },

  saveUserInfo: function (userInfo) {
    let ress = {};
    ress.userInfo = userInfo;

    app.setUserInfo(ress);
    wx.switchTab({
      url: '/pages/index/index', success: function () {

      }, fail: function (e) {
        console.log(e)
      }
    });
  },

})